package boogui.member;

import java.util.Scanner;

public class MemberService implements IMemberService {

	MemberDAO mdao = null;
	MemberLoginDAO mldao = null;

	public MemberService() {
		mdao = new MemberDAO();
		mldao = new MemberLoginDAO();
	}

	@Override
	public void createMember() {
		MemberVO m = new MemberVO();

		System.out.println("1.회원가입");
		Scanner sc = new Scanner(System.in);
		System.out.println("2.아이디 입력");
		m.setMemid(sc.next());
		System.out.println("3.비밀번호 입력");
		m.setMempwd(sc.next());
		System.out.println("4.이름 입력");
		m.setMemname(sc.next());
		System.out.println("5.생년월일 입력");
		m.setMembirth(sc.next());
		System.out.println("6.장르 입력");
		m.setMemgenre(sc.next());
		System.out.println("7.핸드폰 입력");
		m.setMemhp(sc.next());
		System.out.println("8.이메일 입력");
		m.setMememail(sc.next());

		if (mdao.insertMember(m))
			System.out.println("회원가입 완료");
		else
			System.out.println("회원가입 실패");

	}

	@Override
	public void readMember() {
		for (MemberVO m : mdao.selectMember()) {
			System.out.print(m.getMemno());
			System.out.print("/");
			System.out.print(m.getMemid());
			System.out.print("/");
			System.out.print(m.getMempwd());
			System.out.print("/");
			System.out.print(m.getMemname());
			System.out.print("/");
			System.out.print(m.getMembirth());
			System.out.print("/");
			System.out.print(m.getMemgenre());
			System.out.print("/");
			System.out.print(m.getMemhp());
			System.out.print("/");
			System.out.print(m.getMememail());
			System.out.println("/");
		}
	}

	@Override
	public void modifyMember() {
		MemberVO m = new MemberVO();
		Scanner scan = new Scanner(System.in);

		System.out.println("변경할 회원 아이디 입력");

		mldao.selectPwd(scan.next());

		System.out.println("회원의 비밀번호 입력");
		if (scan.next().equals(m.getMempwd())) {
			System.out.println("수정할 비밀번호 입력");
			m.setMempwd(scan.next());
			System.out.println("생년 월일 수정");
			m.setMembirth(scan.next());
			System.out.println("핸드폰 번호 수정");
			m.setMemhp(scan.next());
			System.out.println("E-mail 수정");
			m.setMememail(scan.next());
		} else {
			System.out.println("nono");

		}
		if (mdao.updateMember(m))
			System.out.println("수정성공");
		else
			System.out.println("실패");

	}

	@Override
	public void removeMember() {
		readMember();

		MemberVO mvo = new MemberVO();
		Scanner sc = new Scanner(System.in);
		System.out.println("삭제할 회원의 번호를 입력");
		mvo.setMemno(sc.next());

		if (mdao.deleteMember(mvo))
			System.out.println("회원 삭제 성공");
		else
			System.out.println("회원 삭제 실패");

	}

}
